import com.github.sardine.DavResource;
import org.aarboard.nextcloud.api.NextcloudConnector;
import org.aarboard.nextcloud.api.filesharing.Share;
import org.aarboard.nextcloud.api.filesharing.SharePermissions;
import org.aarboard.nextcloud.api.filesharing.ShareType;
import org.aarboard.nextcloud.api.provisioning.ShareData;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.List;

public class test {
    public static void main(String[] args) throws Exception {
        String serverName = "120.46.138.251";
        boolean useHTTPS = false;
        int port = 8001;
        String userName = "admin";
        String password = "admindev123$%^";


        long startTime = System.currentTimeMillis();
        System.out.println("nextcloud连接startTime====>" + startTime);
        NextcloudConnector nxt = new NextcloudConnector(serverName, useHTTPS, port, userName, password);
        long endTime = System.currentTimeMillis();
        System.out.println("nextcloud连接endTime====>" + endTime);
        System.out.println("连接nextcloud耗时====>" + (endTime - startTime) + "毫秒");
//        //获取文件夹信息
//        List<DavResource> resources = nxt.listFolderContentDavResource("/", 1, false);
//        for (DavResource res : resources) {
//            if (res.getName().equals("webdav")) {
//                continue;
//            }
//            System.out.println(res.getName());
//            System.out.println(res.getPath());
//            System.out.println(res.getContentType());
//            System.out.println(res.getContentLength());
//            System.out.println(res.getModified());
//            System.out.println(res.isDirectory());
//            System.out.println("+++++++++++++++++++++");
//        }
//
//        //上传一个文件
//        File file = new File("C:\\Users\\Administrator\\Desktop\\测试模板表.docx");
//        InputStream input = new FileInputStream(file);    // 通过对象多态性，进行实例化
//        nxt.uploadFile(input, "hanby/" + file.getName());
//        SharePermissions sp = new SharePermissions(2);
//
////        Share s = nxt.doShare("/area/测试结果表.docx", ShareType.PUBLIC_LINK,null,false,null,sp);
//
//        Share s = nxt.doShare("/hanby/测试模板表.docx", ShareType.PUBLIC_LINK, null, false, null, null);
//        boolean b = nxt.editShare(s.getId(), ShareData.PERMISSIONS, "19");
//
//        Share ss = nxt.doShare("/hanby/测试模板表.docx", ShareType.PUBLIC_LINK, null, false, null, null);
////        boolean bb = nxt.editShare(ss.getId(), ShareData.PERMISSIONS, "1");

//        String id = "1509147140950224897";
//        nxt.deleteFolder("/lekang_tempResult");
//        nxt.createFolder("/lekang_tempResult");


//        long downloadstartTime = System.currentTimeMillis();
//        System.out.println("nextcloud下载downloadstartTime====>" + downloadstartTime);

//        File sourcefile = new File("C:\\Users\\Administrator\\Desktop\\aaa\\1508353019549507585.docx");
//        File destfile = new File("C:\\Users\\Administrator\\Desktop\\download\\1508353019549507585.docx");
//        Files.copy(sourcefile.toPath(), destfile.toPath());

        String filePath = "/lekang_temp/1520936142535585794.docx";
        nxt.deleteFolder(filePath);

//
//        nxt.downloadFile("/LkMedicalPrintController.java","C:\\Users\\Administrator\\Desktop\\download");
//


//        long downloadendTime = System.currentTimeMillis();
//        System.out.println("nextcloud下载downloadendTime====>" + downloadendTime);
//        System.out.println("下载nextcloud文件耗时====>" + (downloadendTime - downloadstartTime) + "毫秒");


//        boolean a = nxt.fileExists("/lekang_tempResult/" + "*" + ".docx");
//
//        System.out.println(a);

//        System.out.println(s.getUrl());
////        System.out.println(bb);
//        System.out.println(ss.getUrl());


//        nxt.shutdown();

        //上传一段文字
//        InputStream inputStream = new ByteArrayInputStream("卓工人份热".getBytes());
//        nxt.uploadFile(inputStream, "/AA.txt");

        //下载一个文件到指定目录
//        nxt.downloadFile("/workflow-boot-8.0.jar","D:/360极速浏览器下载/");

        //下载一个文件返回流
        // InputStream input = nxt.downloadFile("/sss/中国/中国/啊.md");

        //（暂时不用）中文下不下来，需要调试（没有压缩成zip）
        //nxt.downloadFolder("","D:/360极速浏览器下载/");

        //下载文件夹，压缩包
        // nxt.downloadFolderToZip("/");


        //修改文件名,如果同名默认替换
        // nxt.move("/赵雷4/新建文本文档.md","/赵雷4/新建文本文档33343.md");

    }


}
